#ifndef MODULE_H_
#define MODULE_H_

#include <stdint.h>
#include <sys/time.h>
#include <sys/types.h>
#include "device.h"
#include "crypto.h"
//#include "keymgt.h"
#include "sec_api.h"
#include "autoconfig.h"
#include "prn_drv.h"
#include "lcd_attr.h"
#include "apitrans.h"


typedef struct {
        uint32_t magic_num;
        uint32_t text_start;
        uint32_t text_end;
        uint32_t data_start;
        uint32_t data_end;
        uint32_t bss_start;
        uint32_t bss_end;
        int (*module_init)(sys_apitrans_t api);
        int (*module_main)(void);
        void* (*module_export)(void);
}module_t;

#define _module_header_entry __attribute__ ((__used__,section (".mod.header")))
#define MODULE_MAGIC    0x72786D64

module_t * load_module(char *name);
void * sys_load_library(char *name);
int sys_run_app(char *name);
const char * get_sys_version(void);


#define PART_NAME_MAX 14
#define MODULE_SHA256_LEN 26
typedef struct {
        uint8_t head;
        uint8_t hash_flag;
        uint8_t public_key;
        uint8_t time[3];
        char name[PART_NAME_MAX]; /* The above 4-byte aligned */
        uint32_t length;
        uint8_t firmware_type;
        uint8_t resev[2];
        uint8_t sha256[32];
        uint8_t end;
}headinfo_t;

typedef struct {
	uint8_t magc[8];
	uint8_t type;
	uint8_t date[7];
	uint32_t length;
	uint8_t owner_svr[12];
	uint8_t sha256[32];
	uint8_t usr_svr[192];
} sysheadinfo_t;	// file head info


int decode_signature(uint8_t * sig, headinfo_t* app, module_t *pmod);
int verify_firmware(char * name);

#endif /* MODULE_H_ */
